
const Essay_Model = require("../models/EssayModel")
const EssayServire = {
    add: (data) => {
        return Essay_Model.create({
            ...data
        })
    },
    get_list: async (id) => {
        return {
            data: await Essay_Model.find().select('-likes -__v -review -browse').limit(10).skip(id).sort({ publish_time: 'desc' }),
            count: await Essay_Model.countDocuments(),
        }
    },
    get_one: async (id) => {
        return await Essay_Model.findOne({
            _id: id
        }).select("-__v")
    },
    update_one_essay: async (data) => {
        return await Essay_Model.updateOne({
            _id: data._id
        }, {
            ...data
        })
    },
    delete_one_essay: async (_id) => {
        return await Essay_Model.deleteOne({
            _id: _id
        })
    }
}

module.exports = EssayServire